import { createStore } from 'redux'

// 相当于vue中的mutation
// reducer 为纯函数
// 必须要有返回值，返回值直接修改state
// 通过dispatch 触发reducer
const reducer = (state, payload) => {
    console.log('触发了', payload)
    switch(payload.type) {
        case 'CHANGE_USER_INFO':
            return {
                ...state,
                userInfo: payload.data
            }
        default:
            return state
    }
}


// 全局状态
const state = {
    title: "2208A",
    userInfo: {}
}

// 创建仓库
const store = createStore(reducer, state);

// 做实验
window.S = store;

export default store
